
public class Test0514a {
    public String countAndSay(int n) {
        String s="1";
        if(n==1) return s;
        int i=1;
        while(i<n) {
        	StringBuffer ss=new StringBuffer();
        	char[] c=s.toCharArray();
        	for(int right=0,left=0;right<s.length();) {
        		while(right<s.length()&&c[right]==c[left])right++;
        		ss.append(right-left);
        		ss.append(c[left]);
        		left=right;
        	}
        	s=new String(ss.toString());
        	i++;
        }
        return s;
    }
}
